package com.ruix.app.ui.usercenter;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.ruix.app.R;
import com.ruix.app.manager.UserManager;
import com.ruix.app.model.User;
import com.ruix.app.model.WebParcel;
import com.ruix.app.network.ApiConstant;
import com.ruix.app.ui.CommonWebActivity;
import com.ruix.app.ui.base.BaseActivity;
import com.ruix.app.widget.CommonTitleBar;

import java.text.DecimalFormat;

/**
 * Created by hadexs on 2017/5/4.
 */

public class PurseActivity extends BaseActivity {
    @Override
    protected int loadViewLayout() {
        return R.layout.activity_purse;
    }

    @Override
    protected void initView() {
        setTitle("钱包");
       TextView moneyView = (TextView) findViewById(R.id.tv_money); //// TODO: 2017/5/4
        User user =  UserManager.getCurrentUser();
        if (user != null && !TextUtils.isEmpty(user.getMoney())){
            int money = Integer.parseInt(user.getMoney());
            double abc = money / 100.0;
            DecimalFormat df = new DecimalFormat("#0.00");
            String result = df.format(abc);
            moneyView.setText(result);
        }  else  {
            moneyView.setText("0.00");
        }
        showDetail();
    }

    private void showDetail(){
        CommonTitleBar titleBar = getTitleBar();
        TextView titleBarRightBtn = titleBar.getRightBtn();
        titleBarRightBtn.setText("明细");
        titleBarRightBtn.setTextColor(getResources().getColor(R.color.color_33));
        titleBarRightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PurseActivity.this, PurseDetailActivity.class);
                startActivity(intent);
            }
        });
    }


    @Override
    protected void initLocalData() {

    }

    @Override
    protected void initListener() {
        findViewById(R.id.tv_comm_question).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebParcel parcel = new WebParcel();
                parcel.setTitle("常见问题");
                parcel.setUrl(ApiConstant.App_Common_Question);
                startActivity(CommonWebActivity.newIntent(PurseActivity.this, parcel));

            }
        });
    }
}
